﻿<Window x:Class="MicroBlogClient.CommentOperator"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:controls="clr-namespace:Rabbit.Controls;assembly=Rabbit.Controls" 
         mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="198"
          xmlns:local="clr-namespace:MicroBlogClient"   Background="Transparent"  Topmost="True"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="mainWindow" Opacity="1.0"
        WindowState="Normal" ShowInTaskbar="False" SizeToContent="Height" ShowActivated="True" WindowStyle="None" AllowsTransparency="True"
        Title="CommentOperator"  MinWidth="324" MaxHeight="400" Width="324">
    <Window.Resources>
        <Storyboard x:Key="StoryBoardPopupAnimation">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="mainWindow">
                <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
                <SplineDoubleKeyFrame KeyTime="0:0:1.5" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="mainWindow">
                <DiscreteObjectKeyFrame KeyTime="0:0:1" Value="{x:Static Visibility.Visible}"/>
                <DiscreteObjectKeyFrame KeyTime="0:0:1.5" Value="{x:Static Visibility.Collapsed}"/>
            </ObjectAnimationUsingKeyFrames>
        </Storyboard>
        <DataTemplate x:Key="CommentsItemTemplate">
            <DockPanel Margin="0,10,0,10" x:Name="grid" Background="Transparent">
                <!--User Picture-->
                <Border VerticalAlignment="Top" Width="40" >
                    <Border BorderBrush="White" DockPanel.Dock="Left" CornerRadius="5" Height="40" Width="40" BorderThickness="1">
                        <Image Stretch="UniformToFill" Source="{Binding User.ProfileImageUrl, Converter={StaticResource ImageConverter}, IsAsync=True}" />
                    </Border>
                </Border>
                <!--Status Text-->
                <StackPanel Margin="10,0,0,0">
                    <!--User/Status Information-->
                    <StackPanel Orientation="Horizontal">
                        <TextBlock TextWrapping="Wrap" Canvas.Top="0" Width="Auto"><Hyperlink CommandParameter="{Binding User.ScreenName}"  Click="link_OnUserNameClicked"><Run Text="{Binding User.ScreenName}"/></Hyperlink></TextBlock>
                        <controls:ImageEx Visibility="{Binding User.Verified, Converter={StaticResource BooleanToVisibilityConverter}}" Source="{StaticResource CertificateUser}" Height="18" Width="20"/>
                        <TextBlock Foreground="Gray" Margin="5,0,0,0"
                                   Visibility="{Binding IsMouseOver,Converter={StaticResource ContrastBooleanToVisibilityConverter},RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}"
                                   Text="{Binding CreatedAt, Converter={StaticResource ResourceKey=DateTimeFormatConverter}, IsAsync=True}"/>
                        <TextBlock  Margin="10,0,0,0" Visibility="{Binding IsMouseOver, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}, Mode=FindAncestor}}"><Hyperlink CommandParameter="{Binding InReplyToStatusId}" Click="ReplyToCommentsHandler" ><Run Text="回复"/></Hyperlink></TextBlock>
                    </StackPanel>
                    <!--Status Inforamtion:Text and Picture(if exist)-->
                    <DockPanel Margin="10,10,0,0">
                        <!--Status text-->
                        <controls:TextBlockEx OnUserNameClicked="link_OnUserNameClicked" Foreground="{DynamicResource StatusForegroundBrush}"  LineHeight="20" Text="{Binding Text, IsAsync=True}" DockPanel.Dock="Top" TextWrapping="Wrap">
                            <controls:TextBlockEx.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="复制" CommandParameter="{Binding Text}" Click="menuCopyStatus_Click"/>
                                </ContextMenu>
                            </controls:TextBlockEx.ContextMenu>
                        </controls:TextBlockEx>
                    </DockPanel> 
                    <TextBlock Margin="0,10,0,0">
                        <TextBlock Text="{Binding Source}" Foreground="Gray" />
                    </TextBlock>
                </StackPanel>
            </DockPanel> 
        </DataTemplate>
    </Window.Resources>
    <Border Style="{DynamicResource MainWindowBorder}" CornerRadius="5">
        <Border CornerRadius="5" BorderThickness="1">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="30"/>
                    <RowDefinition MinHeight="120" Height="*"/>
                </Grid.RowDefinitions>
                <Canvas Height="16" Grid.Row="0" VerticalAlignment="Top" Opacity="0.3" Background="{DynamicResource WindowTitleBackground}" />
                <Canvas Height="32" Grid.Row="0" Background="{DynamicResource TitleBarLeftCornerHighlight}"/>
                <Border BorderBrush="{DynamicResource WindowTitleBarInnerBorder}" CornerRadius="5,5,0,0" Margin="0" BorderThickness="1,1,0,0">
                    <ContentControl>
                        <Canvas Height="32" Grid.Row="0" Margin="5,3,5,0" PreviewMouseLeftButtonDown="Window_PreviewMouseDown">
                            <Image Height="16" Width="16" Source="/Resources/logo16.png"/>
                            <TextBlock Text="{StaticResource AppTitle}" Canvas.Left="22" Style="{DynamicResource AppTitleStyle}"/>
                            <Button  Style="{DynamicResource WindowTitleBarButtonStyle}" Canvas.Right="0"  Click="btnTitleBarClose_Click">
                                <Button.Content>
                                    <controls:ImageEx Source="{DynamicResource CloseButton}" Height="12" Width="14"/>
                                </Button.Content>
                            </Button>
                        </Canvas>
                    </ContentControl>
                </Border>
                <Border Grid.Row="1" Padding="10" CornerRadius="3" Background="White">
                    <Grid> 
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        <TextBlock  Margin="5,0,0,0" MaxHeight="60" VerticalAlignment="Top" TextTrimming="CharacterEllipsis" TextWrapping="Wrap">
                            <TextBlock Text="{Binding RepliedUserName,FallbackValue=韩现龙}" FontWeight="Bold" FontFamily="宋体"   Style="{DynamicResource AppTitleStyle}" Foreground="Black" />
                            <Run Text="{Binding RepliedString,FallbackValue=大家好}" />
                        </TextBlock>
                        <TextBox x:Name="txtReply"  Margin="0,10,0,0"
                                 Text="{Binding InitializedTextBoxContent,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" 
                                 TextWrapping="Wrap"  Height="60" PreviewKeyDown="txtReply_PreviewKeyDown"
                                 AcceptsReturn="True"  MaxLength="140"
                                 Grid.Row="1"/>

                        <Canvas Grid.Row="2" Height="20">
                            <CheckBox Content="同时评论原文" 
                                          Visibility="{Binding IsForwardStatus,Converter={StaticResource BooleanToVisibilityConverter}}"
                                          x:Name="chkCommentOrignalStatus" IsChecked="True"/>
                            <TextBlock Visibility="{Binding IsReplyToStatus,Converter={StaticResource BooleanToVisibilityConverter}}" >
                                    <Hyperlink Click="linkShowComments_Click">
                                        <Run Text="{Binding CommentsCount,StringFormat=显示其他{0}条评论,FallbackValue=显示其他0条评论}"/>
                                    </Hyperlink>
                            </TextBlock>
                            <TextBlock Text="{Binding ProcessingTip}" Canvas.Left="120"/>
                            <Button Canvas.Right="0" IsEnabled="{Binding InitializedTextBoxContent.Length,Converter={StaticResource LessThanOrEqualConverter},ConverterParameter={StaticResource MaxStatusLength}}" Content="发表" x:Name="btnPublish" Click="btnPublish_Click" Grid.Row="2" HorizontalAlignment="Right"/>
                        </Canvas>
                        <Grid Grid.Row="3" Visibility="{Binding IsCommentListVisible,Converter={StaticResource BooleanToVisibilityConverter}}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <ListBox x:Name="lstComment" 
                                  ItemTemplate="{StaticResource ResourceKey=CommentsItemTemplate}" />
                            <local:UCPager x:Name="ucPager"
                                Grid.Row="1" OnFirstPageClick="UCPager_OnFirstPageClick"
                                           OnNextPageClick="UCPager_OnNextPageClick"
                                           OnPreviousePage="UCPager_OnPreviousePage"
                                           />
                        </Grid>
                    </Grid>
                </Border>
            </Grid>
        </Border>
    </Border>
</Window>
